import 'package:demo_proj01/repository/datas/banner_data.dart';
import 'package:demo_proj01/repository/datas/home_list_data.dart';
import 'package:demo_proj01/repository/datas/hot_key_data.dart';
import 'package:demo_proj01/repository/http/dioinstance.dart';

class ApiClient {
  static Future<List<BannerItemData>> getBannerList() async {
    try {
      var response = await DioInstance.instance().getDio().get('/banner/json');
      BannerData bannerData = BannerData.fromJson(response.data);
      return bannerData.data;
    } catch (e) {
      print('解析失败: $e');
      return [];
    }
  }

  static Future<List<HomeListItemData>> getHomeList(int pageIndex) async {
    try {
      var response = await DioInstance.instance().getDio().get(
        '/article/list/$pageIndex/json',
      );
      HomeData homeData = HomeData.fromJson(response.data);
      return homeData.data?.datas ?? [];
    } catch (e) {
      print('解析失败: $e');
      return [];
    }
  }

  static Future<List<HotKeyItemData>> getHotKeyList() async {
    try {
      var response = await DioInstance.instance().getDio().get('/hotkey/json');
      HotKeyData hotKeyData = HotKeyData.fromJson(response.data);
      return hotKeyData.data ?? [];
    } catch (e) {
      print('解析失败: $e');
      return [];
    }
  }
}
